angular.module('starter.router', []).config(function ($stateProvider, $urlRouterProvider, $httpProvider, $ionicConfigProvider, $ocLazyLoadProvider) {

    $stateProvider

    // setup an abstract state for the tabs directive

    // Each tab has its own nav history stack:

        .state('home', {
            url: '/home',
            data: {pageTitle: '首页'},
            templateUrl: 'templates/home.html',
            cache: true,
            controller: 'homeController',
            resolve: {
                deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                    return $ocLazyLoad.load({
                        name: 'starter',
                        insertBefore: '#ng_load_plugins_before',
                        files: [
                        	'css/home.css',
                            'js/controllers/homeController.js'
                        ]
                    });
                }]
            }
        })
        .state('login', {
            url: '/login',
            data: {pageTitle: '登陆'},
            templateUrl: 'templates/login.html',
            cache: false,
            controller: 'loginController',
            resolve: {
                deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                    return $ocLazyLoad.load({
                        name: 'starter',
                        insertBefore: '#ng_load_plugins_before',
                        files: [
                            'js/controllers/loginController.js'
                        ]
                    });
                }]
            }
        })
        .state('bookingLines', {
            url: '/bookingLines',
            data: {pageTitle: '预订'},
            templateUrl: 'templates/booking_lines.html',
            cache: true,
            controller: 'bookingLinesController',
            resolve: {
                deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                    return $ocLazyLoad.load({
                        name: 'starter',
                        insertBefore: '#ng_load_plugins_before',
                        files: [
                            'js/controllers/bookingLinesController.js'
                        ]
                    });
                }]
            }
        })
        .state('booking_plan', {
            url: '/booking_plan',
            data: {pageTitle: '预订-线路详情'},
            templateUrl: 'templates/booking_plan.html',
            params: {line:null,order:null},
            cache: false,
            controller: 'bookingPlanController',
            resolve: {
                deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                    return $ocLazyLoad.load({
                        name: 'starter',
                        insertBefore: '#ng_load_plugins_before',
                        files: [
                        	'lib/iosselect/iosSelect.css',
                        	'lib/iosselect/iscroll.js',
                            'lib/iosselect/iosSelect.js',
                            'lib/require.js',
                            'js/controllers/bookingPlanController.js'
                        ]
                    });
                }]
            }
        })
        .state('booking_date', {
            url: '/booking_date',
            data: {pageTitle: '选择日期'},
            templateUrl: 'templates/booking_date.html',
            params: {line:null,order:null},
            cache: false,
            auth:true,
            controller: 'bookingDateController',
            resolve: {
                deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                    return $ocLazyLoad.load({
                        name: 'starter',
                        insertBefore: '#ng_load_plugins_before',
                        files: [
                        	'lib/calendar_m.js',
                            'js/controllers/bookingDateController.js'
                        ]
                    });
                }]
            }
        })
        .state('booking_passenger', {
            url: '/booking_passenger',
            data: {pageTitle: '乘客信息'},
            templateUrl: 'templates/booking_passenger.html',
            params: {line:null,order:null},
            cache: false,
            auth:true,
            controller: 'bookingPassengerController',
            resolve: {
                deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                    return $ocLazyLoad.load({
                        name: 'starter',
                        insertBefore: '#ng_load_plugins_before',
                        files: [
                        	'lib/iosselect/iosSelect.css',
                            'lib/iosselect/iscroll.js',
                            'lib/iosselect/iosSelect.js',
                            'js/controllers/bookingPassengerController.js'
                        ]
                    });
                }]
            }
        })
        .state('booking_confirm', {
            url: '/booking_confirm',
            data: {pageTitle: '订单确认'},
            templateUrl: 'templates/booking_confirm.html',
            params: {line:null,order:null},
            auth:true,
            cache: false,
            controller: 'bookingConfirmController',
            resolve: {
                deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                    return $ocLazyLoad.load({
                        name: 'starter',
                        insertBefore: '#ng_load_plugins_before',
                        files: [
                            'js/controllers/bookingConfirmController.js'
                        ]
                    });
                }]
            }
        })
        .state('orders', {
            url: '/orders',
            data: {pageTitle: '我的订单'},
            templateUrl: 'templates/orders.html',
            params: {transData: {}},
            cache: false,
            auth:true,
            controller: 'ordersController',
            resolve: {
                deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                    return $ocLazyLoad.load({
                        name: 'starter',
                        insertBefore: '#ng_load_plugins_before',
                        files: [
                            'js/controllers/ordersController.js'
                        ]
                    });
                }]
            }
        })
        .state('order_toPay', {
            url: '/order_toPay/:orderId',
            data: {pageTitle: '待支付'},
            templateUrl: 'templates/order_toPay.html',
            params: {orderId: null},
            cache: false,
            auth:true,
            controller: 'orderToPayController',
            resolve: {
                deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                    return $ocLazyLoad.load({
                        name: 'starter',
                        insertBefore: '#ng_load_plugins_before',
                        files: [
                            'js/controllers/orderToPayController.js'
                        ]
                    });
                }]
            }
        })
        .state('order_hadPay', {
            url: '/order_hadPay/:orderId',
            data: {pageTitle: '已支付'},
            templateUrl: 'templates/order_hadPay.html',
            params: {orderId: null},
            cache: false,
            auth:true,
            controller: 'orderHadPayController',
            resolve: {
                deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                    return $ocLazyLoad.load({
                        name: 'starter',
                        insertBefore: '#ng_load_plugins_before',
                        files: [
                            'js/controllers/orderHadPayController.js'
                        ]
                    });
                }]
            }
        })
        .state('bus_code', {
            url: '/bus_code/:orderId',
            data: {pageTitle: '乘车码'},
            templateUrl: 'templates/bus_code.html',
            params: {orderId: null},
            cache: false,
            auth:true,
            controller: 'busCodeController',
            resolve: {
                deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                    return $ocLazyLoad.load({
                        name: 'starter',
                        insertBefore: '#ng_load_plugins_before',
                        files: [
                            'js/controllers/busCodeController.js'
                        ]
                    });
                }]
            }
        })
        .state('passenger_code', {
            url: '/passenger_code',
            data: {pageTitle: '乘车码'},
            templateUrl: 'templates/passenger_code.html',
            params: {passenger : {}},
            cache: false,
            auth:true,
            controller: 'passengerCodeController',
            resolve: {
                deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                    return $ocLazyLoad.load({
                        name: 'starter',
                        insertBefore: '#ng_load_plugins_before',
                        files: [
                            'js/controllers/passengerCodeController.js'
                        ]
                    });
                }]
            }
        })
        .state('refund_detail', {
            url: '/refund_detail/:orderBackId',
            data: {pageTitle: '退款'},
            templateUrl: 'templates/refund_detail.html',
            params: {orderBackId: null},
            cache: false,
            auth:true,
            controller: 'refundDetailController',
            resolve: {
                deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                    return $ocLazyLoad.load({
                        name: 'starter',
                        insertBefore: '#ng_load_plugins_before',
                        files: [
                            'js/controllers/refundDetailController.js'
                        ]
                    });
                }]
            }
        })

        .state('refund', {
            url: '/refund/:orderId',
            data: {pageTitle: '退款'},
            templateUrl: 'templates/refund.html',
            params: {orderId: null},
            cache: false,
            auth:true,
            controller: 'refundController',
            resolve: {
                deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                    return $ocLazyLoad.load({
                        name: 'starter',
                        insertBefore: '#ng_load_plugins_before',
                        files: [
                            'js/controllers/refundController.js'
                        ]
                    });
                }]
            }
        })
        .state('order_pay', {
            url: '/order_pay/:orderId',
            data: {pageTitle: '订单支付'},
            templateUrl: 'templates/order_pay.html',
            params: {orderId : null},
            cache: false,
            auth:true,
            controller: 'orderPayController',
            resolve: {
                deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                    return $ocLazyLoad.load({
                        name: 'starter',
                        insertBefore: '#ng_load_plugins_before',
                        files: [
                            'js/controllers/orderPayController.js'
                        ]
                    });
                }]
            }
        })
        .state('survey', {
            url: '/survey',
            data: {pageTitle: '出行调查'},
            templateUrl: 'templates/survey.html',
            params: {transData: {}},
            cache: false,
            controller: 'surveyController',
            resolve: {
                deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                    return $ocLazyLoad.load({
                        name: 'starter',
                        insertBefore: '#ng_load_plugins_before',
                        files: [
							'lib/iosselect/iosSelect.css',
							'lib/iosselect/iscroll.js',
							'lib/iosselect/iosSelect.js',
                            'js/controllers/surveyController.js'
                        ]
                    });
                }]
            }
        })
        .state('instruction', {
            url: '/instruction',
            data: {pageTitle: '乘客须知'},
            templateUrl: 'templates/instruction.html',
            params: {transData: {}},
            cache: false,
            controller: 'instructionController',
            resolve: {
                deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                    return $ocLazyLoad.load({
                        name: 'starter',
                        insertBefore: '#ng_load_plugins_before',
                        files: [
                            'js/controllers/instructionController.js'
                        ]
                    });
                }]
            }
        })
        .state('instruction_detail', {
            url: '/instruction_detail',
            data: {pageTitle: '乘客须知明细'},
            templateUrl: 'templates/instruction_detail.html',
            params: {transData: {}},
            cache: false,
            controller: 'instructionDetailController',
            resolve: {
                deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                    return $ocLazyLoad.load({
                        name: 'starter',
                        insertBefore: '#ng_load_plugins_before',
                        files: [
                            'js/controllers/instructionDetailController.js'
                        ]
                    });
                }]
            }
        })
        .state('notices', {
            url: '/notices',
            data: {pageTitle: '服务公告'},
            templateUrl: 'templates/notices.html',
            params: {transData: {}},
            cache: false,
            controller: 'noticesController',
            resolve: {
                deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                    return $ocLazyLoad.load({
                        name: 'starter',
                        insertBefore: '#ng_load_plugins_before',
                        files: [
                            'js/controllers/noticesController.js'
                        ]
                    });
                }]
            }
        })
        .state('notices_detail', {
            url: '/notices_detail',
            data: {pageTitle: '公告明细'},
            templateUrl: 'templates/notices_detail.html',
            params: {transData: {}},
            cache: false,
            controller: 'noticesDetailController',
            resolve: {
                deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                    return $ocLazyLoad.load({
                        name: 'starter',
                        insertBefore: '#ng_load_plugins_before',
                        files: [
                            'js/controllers/noticesDetailController.js'
                        ]
                    });
                }]
            }
        })
        .state('aboutus', {
            url: '/aboutus',
            data: {pageTitle: '联系我们'},
            templateUrl: 'templates/aboutus.html',
            params: {transData: {}},
            cache: false,
            controller: 'aboutusController',
            resolve: {
                deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                    return $ocLazyLoad.load({
                        name: 'starter',
                        insertBefore: '#ng_load_plugins_before',
                        files: [
                            'js/controllers/aboutusController.js'
                        ]
                    });
                }]
            }
        })
        .state('boards', {
            url: '/boards',
            data: {pageTitle: '留言板'},
            templateUrl: 'templates/boards.html',
            params: {transData: {}},
            cache: false,
            auth:true,
            controller: 'boardsController',
            resolve: {
                deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                    return $ocLazyLoad.load({
                        name: 'starter',
                        insertBefore: '#ng_load_plugins_before',
                        files: [
                            'js/controllers/boardsController.js'
                        ]
                    });
                }]
            }
        })
        .state('board_edit', {
            url: '/board_edit',
            data: {pageTitle: ''},
            templateUrl: 'templates/board_edit.html',
            params: {transData: {}},
            cache: false,
            auth:true,
            controller: 'boardEditController',
            resolve: {
                deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                    return $ocLazyLoad.load({
                        name: 'starter',
                        insertBefore: '#ng_load_plugins_before',
                        files: [
                            'js/controllers/boardEditController.js'
                        ]
                    });
                }]
            }
        })
    ;

    // if none of the above states are matched, use this as the fallback
    // $urlRouterProvider.otherwise('/login');
    $urlRouterProvider.otherwise(function ($injector, $location) {
        $location.path('/home');
    });
});
    
